# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=giflib
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.2.1
pkgrel=3
pkgdesc="A library for reading and writing gif images (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://sourceforge.net/projects/giflib"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "xmlto")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs' 'strip')
source=("https://downloads.sourceforge.net/sourceforge/giflib/${_realname}-${pkgver}.tar.gz"
        "001-mingw-build.patch"
        "giflib_quantize.patch")
sha256sums=('31da5562f44c5f15d63340a09a4fd62b48c45620cd302f77a6d9acf0077879bd'
            '4929fac57595dd37224313841153e24b594a7a89328fe573d8b44faea0345c54'
            '29f0d5a98520cf908a11325987ca9ef2454ca8cb85ce9815b75a52956b9df28a')
noextract=(${_realname}-${pkgver}.tar.gz)

prepare() {
  [[ -d ${srcdir}/${_realname}-${pkgver} ]] && rm -rf ${srcdir}/${_realname}-${pkgver}
  tar -xzf ${srcdir}/${_realname}-${pkgver}.tar.gz -C ${srcdir} || true

  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/001-mingw-build.patch"
  # https://src.fedoraproject.org/rpms/giflib/c/109bf038d703a471b857aba44af673be103d7079
  patch -Np1 -i "${srcdir}/giflib_quantize.patch"
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  make
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  make DESTDIR="${pkgdir}" PREFIX="${MINGW_PREFIX}" install
}
